/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */

#ifndef BOARDMENCOLORSQ_H_
#define BOARDMENCOLORSQ_H_

#include <boost/cstdint.hpp>
#include <boost/array.hpp>

#include "BoardMenSq.h"

template<class Br, class Sq, class Cl>
class BoardMenColorSq
	: public BoardMenSq<BoardMenColorSq<Br,Sq,Cl>,Br,Sq> {

public:
	typedef Sq Square;
	typedef Cl Color;

	static BoardMenColorSq<Br,Sq,Cl> begin(const Board& board) {
		return BoardMenColorSq<Br,Sq,Cl>::begin(board, board.sideToMove());
	}

	static BoardMenColorSq<Br,Sq,Cl> begin(const Board& board, const Color color) {
		return BoardMenColorSq<Br,Sq,Cl>(board, color);
	}
public:
	 BoardMenColorSq<Br,Sq,Cl>()
		: BoardMenSq<BoardMenColorSq<Br,Sq,Cl>,Br,Sq>() {


	 }

	 BoardMenColorSq<Br,Sq,Cl>(const Board& board, const Color color)
		: BoardMenSq<BoardMenColorSq<Br,Sq,Cl>,Br,Sq>(board), color(color) {

		if ( !this->me_c().predicate() )
			this->me().increment();
	 }

	bool predicate() const {
		return !this->board->isEmpty(*this->square) &&
				(*this->board)[*this->square].color() == this->color;
	}
protected:
	Color color;
};

#endif /* BOARDMENCOLORSQ_H_ */
